package com.pengliu.util;

import java.util.Random;

public class RandomUtil {
	public static String base = "abcdefghijklmnopqrstuvwxyz0123456789";
	public static String getRandomString(int length) { //length表示生成字符串的长度
	    Random random = new Random();
	    StringBuffer sb = new StringBuffer();   
	    int number = 0;
	    for (int i = 0; i < length; i++) {   
	        number = random.nextInt(base.length());   
	        sb.append(base.charAt(number));   
	    }
	    return sb.toString();
	}
	public static String getRandomString(String randStr , int length) { //length表示生成字符串的长度
	    Random random = new Random();
	    StringBuffer sb = new StringBuffer();   
	    int number = 0;
	    for (int i = 0; i < length; i++) {   
	        number = random.nextInt(randStr.length());   
	        sb.append(randStr.charAt(number));   
	    }
	    return sb.toString();   
	}
	/**
	 * user: pengliu
	 * date: 2017年12月1日
	 * desc: 获取范围随机数
	 * @param min 最小值
	 * @param max 最大值
	 * 例如:min=1,max=3则随机值=1,2,3
	 * @return
	 * @author pengliu
	 */
	public static int getRangeRandom(int min,int max) {
		return new Random().nextInt(max-min+1)+min;
	}
}
